package br.unisinos.principal;

import java.util.ArrayList;

import br.unisinos.arquivos.DirectoryEntry;
import br.unisinos.servers.Server;
import br.unisinos.servers.TcpServer;

public class Main {

	/**
	 * @param args
	 * 
	 * This method uses as base the Daniel's code do run the threads;
	 */
	public static void main(String[] args) {
		
		Thread remoteCommThread = null;
        Thread localCommThread = null;
        Server server = null;
        TcpServer tcpServer = null;
        ArrayList<DirectoryEntry> entries = new ArrayList<DirectoryEntry>();
        String[] dirNames = new String[1];
        
        // for now it will be manual
        //dirNames[0] = new String("/home/rcsd/danielstefani/Desktop/teste");
        //dirNames[0] = new String("/var/cache/apt/archives");
        //dirNames[0] = new String("/opt/files4");
        dirNames[0] = new String("C:\\workarea\\tmp");
        //dirNames[0] = new String("/home/daniel/Desktop/etc");
        
        /* get the information in the directories */
        for (int i=0; i<dirNames.length; i++) {
            boolean flag = false;
            
            DirectoryEntry entry = new DirectoryEntry(dirNames[i]);
            flag = entry.readShare();
            
            if (flag)
                entries.add(entry);
        }
        
        tcpServer = new TcpServer(entries);
        remoteCommThread = new Thread(tcpServer);
        remoteCommThread.start();
        
        server = new Server(entries);
        localCommThread = new Thread(server);
        localCommThread.start();
        
        try {
            remoteCommThread.join();
            remoteCommThread.join();
        }
        catch (Exception e) { }
		

	}

}
